package br.domsd.pocketcontrol;

import java.util.Calendar;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import br.domsd.pocketcontrol.action.MonthExpensesActivityActionListener;

public class MonthExpensesActivity extends Activity {

	private MonthExpensesActivityActionListener actionListener;
	
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
    	actionListener = new MonthExpensesActivityActionListener(this);
    	
    	super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_month_expenses);
        
    	String period = getIntent().getExtras().getString("openedPeriod");
    	
    	setTitle(period);
    	
    	Button btnLaunch = (Button) findViewById(R.id.btnLaunch);
    	btnLaunch.setOnClickListener(actionListener);
    	
    	DatePicker datePicker = (DatePicker) findViewById(R.id.datePicker);
    	datePicker.init(getCurrentYear(), getCurrentMonth(), getCurrentDay(), null);
    

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        getMenuInflater().inflate(R.menu.activity_month_expenses, menu);
        return true;
    }
    
    
    public String getAmmountToLaunch()
    {
    	EditText ammount = (EditText) findViewById(R.id.ammount);

    	return ammount.getText().toString();
    }
    
    public String getDate()
    {
    	DatePicker datePicker = (DatePicker) findViewById(R.id.datePicker);
    	
    	StringBuilder date = new StringBuilder();
    	date.append(datePicker.getDayOfMonth());
    	date.append("/");
    	date.append(datePicker.getMonth());
    	date.append("/");
    	date.append(datePicker.getYear());
    	
    	return date.toString();
    }
    
    private int getCurrentYear()
    {
    	Calendar calendar = Calendar.getInstance();
    	
    	int year = calendar.get(Calendar.YEAR);
    	return year;
    }
    
    private int getCurrentMonth()
    {
    	Calendar calendar = Calendar.getInstance();
    	
    	int month = calendar.get(Calendar.MONTH);
    	return month;
    }
    
    private int getCurrentDay()
    {
    	Calendar calendar = Calendar.getInstance();
    	
    	int day = calendar.get(Calendar.DAY_OF_MONTH);
    	return day;
    }
}
